package com.lokiy.kit.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import com.lokiy.annotation.FragmentInfo
import com.lokiy.core.fragment.ViewBindingFragment
import com.lokiy.kit.databinding.FragmentClipBinding
import com.lokiy.kit.ext.setupToolbar
import com.lokiy.kit.widget.ClipBoundDrawable

/**
 *
 * @author Lokiy
 * @date 2023-10-23 16:39
 */
@FragmentInfo("drawable 剪切")
class ClipFragment : ViewBindingFragment<FragmentClipBinding>() {

    @SuppressLint("ClickableViewAccessibility")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        setupToolbar(binding.toolbar)

        val clipBoundDrawable = ClipBoundDrawable(binding.imageView.drawable)
        binding.imageView.setImageDrawable(clipBoundDrawable)

        binding.imageView.setOnTouchListener { v, event ->
            if (event.action == MotionEvent.ACTION_DOWN) {
                val x = event.x.toInt()
                val y = event.y.toInt()
                clipBoundDrawable.setClipBounds(x - 50, y - 50, x + 50, y + 50)
            }
            false
        }
    }

}